package com.example.demo.controller;

import com.example.demo.mapper.MessageMapper;
import com.example.demo.model.Message;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController
public class MessageController {

    @Autowired
    private MessageMapper messageMapper;

    @RequestMapping("/message")
    public Object getMessage(Integer sessionId)
    {
        List<Message> messages = messageMapper.getMessageBySessionId(sessionId);

        //对查询结果逆序排列 因为从数据库查询出来的结果是最新的在前面但是显示是最新的在最下面
        Collections.reverse(messages);
        return messages;
    }
}
